package com.kunlun.basedata.organize.service.impl;

import com.kunlun.basedata.organize.dao.IPostDao;
import com.kunlun.basedata.organize.model.CompanyModel;
import com.kunlun.basedata.organize.model.PostModel;
import com.kunlun.basedata.organize.service.IPostService;
import com.kunlun.basedata.utils.CommonUtil;
import com.kunlun.common.model.Page;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 岗位业务Service类
 */
@Service
@Transactional
public class PostService implements IPostService {

    private final Logger logger = LogManager.getLogger();

    @Autowired
    private IPostDao postDao;

    @Override
    public Page getPostPage(PostModel postModel, int currentPage, int pageSize) throws Exception {
        int startIndex = (currentPage - 1) * pageSize;
        Map<String, Object> queryMap = CommonUtil.packageQueryMap(postModel, startIndex, pageSize);
        int count = postDao.getPostCount(queryMap);
        List<PostModel> allPost = postDao.getPostPage(queryMap);

        Page<PostModel> page = new Page<>();
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        page.setTotal(count);
        page.setRecords(allPost);
        return page;
    }

    @Override
    public List<PostModel> getPostList(Map<String, Object> queryMap) throws Exception {
        return postDao.getPostList(queryMap);
    }

    @Override
    public void addPost(PostModel postModel) throws Exception {
        postModel.setId(CommonUtil.generateUUID());
        postDao.addPost(postModel);
    }

    @Override
    public void updatePost(PostModel postModel) throws Exception {
        postDao.updatePost(postModel);
    }

    @Override
    public void deletePost(List<String> list) throws Exception {
        postDao.deletePost(list);
    }
}
